package views;

import logicBusiness.CertificadoBL;
import logicBusiness.DocumentoBL;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author viviana
 */
public class InterfazCertificado extends javax.swing.JFrame {

    /** Creates new form InterfazCertificado */
    public InterfazCertificado() {
        initComponents();

        java.util.Date d = new Date();
        String date = d.getDate() + "/" + (d.getMonth() + 1) + "/" + (d.getYear() + 1900);
        CTFechaCerti.setText(date);

        CertificadoBL bo1 = new CertificadoBL();
        Integer m = bo1.resultado();
        String r = m.toString();
        CTNumCerti.setText(r);

        DocumentoBL bo = new DocumentoBL();
        Integer b = bo.resultado();
        String p = b.toString();
        doc.setText(p);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        PanelCertificacion = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        CTNombreCerti = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        CTDNICerti = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        CTCiudadCerti = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        CTNumCerti = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        CTCursoCerti = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        CTPeriodoCerti = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        CTMateriasCerti = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        CTSumaHorasCerti = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        doc = new javax.swing.JTextField();
        CTFechaCerti = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        BCrearCertificado = new javax.swing.JButton();
        BCancelar = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText(" CERTIFICADO");

        PanelCertificacion.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("LA INSTITUCION EDUCATIVA");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("CERTIFICAN:");

        jLabel5.setText("Que el Estudiante");

        jLabel6.setText("identificado con el Documento de Identidad ");

        jLabel7.setText("de ");

        jLabel8.setText("Nº");

        CTNumCerti.setEditable(false);

        jLabel9.setText("Bogotá, ");

        jLabel10.setText("esta matriculado en el grado");

        jLabel11.setText("de programa Académico de la Institución, durante");

        jLabel12.setText("el periodo ");

        jLabel13.setText("con el siguiente numero de materias ");

        jLabel14.setText("que suman");

        jLabel15.setText("horas en total.");

        doc.setEditable(false);
        doc.setForeground(new java.awt.Color(240, 240, 240));
        doc.setBorder(null);

        CTFechaCerti.setEditable(false);

        javax.swing.GroupLayout PanelCertificacionLayout = new javax.swing.GroupLayout(PanelCertificacion);
        PanelCertificacion.setLayout(PanelCertificacionLayout);
        PanelCertificacionLayout.setHorizontalGroup(
            PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelCertificacionLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 406, Short.MAX_VALUE)
                .addComponent(doc, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(109, 109, 109))
            .addGroup(PanelCertificacionLayout.createSequentialGroup()
                .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, PanelCertificacionLayout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(CTMateriasCerti, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CTSumaHorasCerti, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel15)
                        .addGap(98, 98, 98))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, PanelCertificacionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(CTNumCerti, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(CTFechaCerti, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(PanelCertificacionLayout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(PanelCertificacionLayout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(CTPeriodoCerti, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE))
                            .addGroup(PanelCertificacionLayout.createSequentialGroup()
                                .addComponent(CTDNICerti, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(CTCiudadCerti, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel10)
                                .addGap(18, 18, 18)
                                .addComponent(CTCursoCerti, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))
                            .addGroup(PanelCertificacionLayout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(18, 18, 18)
                                .addComponent(CTNombreCerti, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel6)))))
                .addContainerGap())
            .addGroup(PanelCertificacionLayout.createSequentialGroup()
                .addGap(172, 172, 172)
                .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3))
                .addContainerGap(257, Short.MAX_VALUE))
        );
        PanelCertificacionLayout.setVerticalGroup(
            PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelCertificacionLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(doc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(CTNumCerti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(CTFechaCerti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(47, 47, 47)
                .addComponent(jLabel3)
                .addGap(13, 13, 13)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(CTNombreCerti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(CTDNICerti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel7))
                    .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(CTCiudadCerti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel10)
                        .addComponent(CTCursoCerti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11)
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(CTPeriodoCerti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(PanelCertificacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(CTSumaHorasCerti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(CTMateriasCerti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13))
                .addContainerGap(33, Short.MAX_VALUE))
        );

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/escudo.jpg"))); // NOI18N

        BCrearCertificado.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BCrearCertificado.setText("Crear Certificado");
        BCrearCertificado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BCrearCertificadoActionPerformed(evt);
            }
        });

        BCancelar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BCancelar.setText("Cancelar");
        BCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(125, 125, 125)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(175, 175, 175)
                        .addComponent(BCrearCertificado)
                        .addGap(78, 78, 78)
                        .addComponent(BCancelar))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(PanelCertificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(266, 266, 266)
                        .addComponent(jLabel1)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(PanelCertificacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BCrearCertificado)
                    .addComponent(BCancelar))
                .addGap(22, 22, 22))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BCancelarActionPerformed

        this.setVisible(false);

        // TODO add your handling code here:
    }//GEN-LAST:event_BCancelarActionPerformed

    private void BCrearCertificadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BCrearCertificadoActionPerformed

        if (CTNumCerti.getText().equals("") || CTNombreCerti.getText().equals("")
                || CTDNICerti.getText().equals("") || CTCiudadCerti.getText().equals("")
                || CTCursoCerti.getText().equals("") || CTPeriodoCerti.getText().equals("")
                || CTMateriasCerti.getText().equals("") || CTSumaHorasCerti.getText().equals("")) {
            JOptionPane.showMessageDialog(this, "Debe digitar los datos completos "
                    + "para crear un Certificado", null, JOptionPane.ERROR_MESSAGE);
        } else {

            CertificadoBL bo = new CertificadoBL();
            int ok = bo.encontrarCertificado(Integer.parseInt(CTNumCerti.getText()));
            if (ok == 1) {
                JOptionPane.showMessageDialog(this, "Ocurrio un error al crear el "
                        + "Certificado", "El Numero del Certificado ya existe ",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                ok = bo.crearCertificado(Integer.parseInt(CTNumCerti.getText()),
                        Integer.parseInt(doc.getText()), CTNombreCerti.getText(),
                        Integer.parseInt(CTDNICerti.getText()), CTCiudadCerti.getText(),
                        CTPeriodoCerti.getText(), Integer.parseInt(CTMateriasCerti.getText()),
                        Integer.parseInt(CTSumaHorasCerti.getText()), CTCursoCerti.getText());


                if (ok == 1) {
                    JOptionPane.showMessageDialog(this, "Se ha creado el Certificado"
                            + "con exito", "Creacion exitosa !!!",
                            JOptionPane.INFORMATION_MESSAGE);

                    this.setVisible(false);
                } else {
                    JOptionPane.showMessageDialog(this, "Ocurrio un error al crear"
                            + " EL Certificado", "Creacion fallida", JOptionPane.ERROR_MESSAGE);
                }
            }


        }
        // TODO add your handling code here:
    }//GEN-LAST:event_BCrearCertificadoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazCertificado().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BCancelar;
    private javax.swing.JButton BCrearCertificado;
    private javax.swing.JTextField CTCiudadCerti;
    private javax.swing.JTextField CTCursoCerti;
    private javax.swing.JTextField CTDNICerti;
    private javax.swing.JTextField CTFechaCerti;
    private javax.swing.JTextField CTMateriasCerti;
    private javax.swing.JTextField CTNombreCerti;
    private javax.swing.JTextField CTNumCerti;
    private javax.swing.JTextField CTPeriodoCerti;
    private javax.swing.JTextField CTSumaHorasCerti;
    private javax.swing.JPanel PanelCertificacion;
    private javax.swing.JTextField doc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    // End of variables declaration//GEN-END:variables
}
